package com.cloud.mall.mapper;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.cloud.mall.dto.CategoryQueryDto;
import com.cloud.mall.entity.Category;

import java.util.List;

public interface CategoryMapper extends BaseMapper<Category> {

    default List<Category> selectListByQueryDto(CategoryQueryDto queryDto) {
        return this.selectList(new LambdaQueryWrapper<Category>()
                .in(CollUtil.isNotEmpty(queryDto.getIds()), Category::getId, queryDto.getIds())
                .eq(queryDto.getStatus() != null, Category::getStatus, queryDto.getStatus())
                .eq(queryDto.getLevel() != null, Category::getLevel, queryDto.getLevel())
                .like(StringUtils.isNotBlank(queryDto.getName()), Category::getName, queryDto.getName())
        );
    }
}